<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div>
    <h1>微博首页</h1>
    <div v-if="isLogin">
        <h3>欢迎{{user.nickname}}的到来</h3>
        <a href="/insert.html">发微博</a>
        <a href="javascript:void (0)" @click="logout()">退出登录</a>
    </div>
    <div v-else>
        <a href="/reg.html">注册</a>
        <a href="/login.html">登录</a>
    </div>
</div>
</body>
<!--引入axios和vue框架文件-->
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<script>
    let v = new Vue({
        el:"body>div",
        data:{
            isLogin:false,
            user:{}
        },
        methods:{
            logout(){
                if (confirm("您确定要退出吗？")){
                    axios.get("/logout").then(function (response){
                        v.isLogin =false;
                    })
                }


            }

        },
        created:function () {
            axios.get("/currentUser").then(function (response) {
                v.user = response.data;
                v.isLogin = !response.data == "";
            })
        }
    })
</script>
</html>